<?php

namespace App\Http\Controllers\v1;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class BaseController extends Controller
{
    public function success($title = '操作成功', $data = array(),$status_code = 200)
    {
        return response()->json(array(
            'message' => $title,
            'data' => $data,
            'code' => 1,
            'status_code' => $status_code,
            'debug' => '',
            'time' => date('Y-m-d H:i:s')
        ), 200) ->setEncodingOptions(JSON_UNESCAPED_UNICODE);
    }

    public function error($title = '操作失败', $data = array(), $status_code = 400, $code = 0)
    {
        return response()->json(array(
            'message' => $title,
            'data' => $data,
            'code' => $code,
            'status_code' => $status_code,
            'debug' => '',
            'time' => date('Y-m-d H:i:s')
        ), 200)-> setEncodingOptions(JSON_UNESCAPED_UNICODE);
    }

    public function rsuccess($message = '操作成功', $data = array(), $code = '')
    {
        return array('code' => 1, 'message' => $message, 'data' => $data, 'time' => date('Y-m-d H:i:s'));
    }

    public function rerror($message = '操作失败', $data = array(), $error_code = '')
    {
        return array('code' => 0, 'message' => $message, 'data' => $data, 'error_code' => $error_code, 'time' => date('Y-m-d H:i:s'));
    }


}
